package Hxw3DEngine.core.display
{
	import flash.display3D.Context3D;
	import Hxw3DEngine.asset.parsers.texture.CubeBitmapVO;
	import Hxw3DEngine.core.component.renderer.MeshRenderer;
	import Hxw3DEngine.core.Resource.texture.CubeBitmapTexture;
	import flash.display.BitmapData;
	import Hxw3DEngine.asset.parsers.bson.vo.Stream;
	import Hxw3DEngine.core.Resource.geometry.ResourceGeometry;
	import Hxw3DEngine.core.Resource.texture.CubeBitmapTexture;
	import Hxw3DEngine.core.materials.SkyboxMaterial;
	
	
	public class SkyBox extends GameObject
	{
		private var vertexData:Vector.<Number> = new <Number>[
			-1, 1, -1,
			1, 1, -1,
			1, 1, 1,
			-1, 1, 1,
			-1, -1, -1,
			1, -1, -1,
			1, -1, 1,
			-1, -1, 1
		];
		
		private var indexData:Vector.<uint> = new <uint>[
			0, 1, 2, 2, 3, 0,
			6, 5, 4, 4, 7, 6,
			2, 6, 7, 7, 3, 2,
			4, 5, 1, 1, 0, 4,
			4, 0, 3, 3, 7, 4,
			2, 1, 5, 5, 6, 2
		];
		
		
		public function SkyBox(posX:BitmapData, negX:BitmapData, posY:BitmapData, negY:BitmapData, posZ:BitmapData, negZ:BitmapData)
		{
			var mesh:MeshRenderer = new MeshRenderer;
			addComponent(mesh);
			mesh.geometry = new ResourceGeometry;
			mesh.geometry.createFromStreams(indexData, 8,[Stream.fromVector(Stream.stream_positions, vertexData)]);
			mesh.material = new SkyboxMaterial(CubeBitmapTexture.create(posX, negX, posY, negY, posZ, negZ));
		}
	}
}